package cn.hh.hrm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 认证配置
 */
@Configuration //配置类
@EnableWebSecurity  //开启安全配置
public class HrmWebSecurityAuthenConfig extends WebSecurityConfigurerAdapter{
    //用户信息  写一个类实现接口  自定义认证流程
    //密码解密器
    @Bean
    public PasswordEncoder  getEncoder(){
        return NoOpPasswordEncoder.getInstance();
       /* return  new BCryptPasswordEncoder();*/
    }
    //http安全配置

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/login").permitAll()
                .anyRequest().authenticated()
                .and().formLogin()
                .successForwardUrl("/success")
                .and().logout().permitAll()
                .and().csrf().disable();
    }
}
